﻿using System;
using System.Web;
using Microsoft.SharePoint;
using System.IO;
using System.Drawing;
using SPThumbnailExtender.Interne;
using SPThumbnailExtender.Handler;

namespace SPThumbnailExtender
{
    public class MobileDwgHandler : IHttpHandler
    {
        /// <summary>
        /// You will need to configure this handler in the web.config file of your 
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            //write your handler implementation here.
            string strQDwg = context.Request.QueryString["dwg"];
            string strWidth = context.Request.QueryString["width"];
            string strHeight = context.Request.QueryString["height"];
            string strCount = context.Request.QueryString["count"];

            int? _imgWidth=null;
            int? _imgHeight=null;
            bool? _bCount=null;
            bool? _bCache=null;
            int imgWidth;
            if(int.TryParse(strWidth, out imgWidth))
            {
                _imgWidth=imgWidth;
            }
            int imgHeight;
            if(int.TryParse(strHeight, out imgHeight))
            {
                _imgHeight=imgHeight;
            }
            int _iPage = 0;

            bool bCache;
            if(bool.TryParse(context.Request["usecache"], out bCache))
            {
                _bCache=bCache;
            }

            bool bCount;
            if(bool.TryParse(strCount, out bCount))
            {
                _bCount=bCount;
            }
            HandlerHelper.ProcessRequest(context,strQDwg,_imgWidth,_imgHeight,_iPage,_bCount,_bCache,typeof(ThumbnailDWG));

        }
        #endregion
    }
}
